/** 
 * UIMA Connectors
 * Copyright (C) 2010  Nicolas Hernandez
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package fr.univnantes.lina.uima.connectors.ftb;

import java.util.HashMap;
import java.util.Map;

import fr.univnantes.lina.uima.connectors.tagset.TagsetMapper;

/**
 * @author hernandez
 *
 */
public class FTB2FTBPlusPOSTagMapper_Impl implements TagsetMapper {


	private static String cat = "cat";
	private static String subcat = "subcat";
	private static String mph = "mph";

	private static String mood = "mood";
	private static String lemma = "lemma";
	private static String tense = "tense";

	/**
	 * Map the ftb morpho-syntax features of a word to ftb+ tag 
	 * See Crabbe and Candito TALN'08 for the mapping table
	 * @see fr.univnantes.lina.uima.connectors.corpus.ftb.POSTagsetMapping_Interface#mapTag(java.util.Map)
	 * @return the ftb+ tag 
	 */
	@Override
	public String mapTag (Map<String, Object> wordMorphoSyntaxFeatures) {
		String tag = "U"; // stands for Unknown or Undefined

		// 1 cat V mode indicatif
		if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("V") 
				&& (((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("C") 
						|| ((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("F") 
						|| ((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("I") 
						|| ((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("J") 
						|| ((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("P") ) ) {
			tag = "V";
		}
		// 2 cat V mode imperatif		
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("V") 
				&& (((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("Y")) ) {
			tag = "VIMP";
		}
		// 3 cat V mode impératif		
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("V") 
				&& (((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("Y")) ) {
			tag = "VIMP";
		}
		// 4 cat V mode infinitif		
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("V") 
				&& (((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("W")) ) {
			tag = "VINF";
		}	
		// 5 cat V mode subjonctif		
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("V") 
				&& (((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("S") 
						|| ((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("T")) ) {
			tag = "VS";
		}
		// 6 cat V mode participe passé		
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("V") 
				&& (((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("K")) ) {
			tag = "VPP";
		}	
		// 7 cat V mode participe présent		
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("V") 
				&& (((String)wordMorphoSyntaxFeatures.get(mood)).equalsIgnoreCase("G")) ) {
			tag = "VPR";
		}
		// 8 cat N  subcat P	
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("N") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("P")) ) {
			tag = "NP";
		}	
		// 9 cat N  subcat C	
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("N") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("C")) ) {
			tag = "NC";
		}	
		// 10 cat C  subcat P	
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("C") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("S")) ) {
			tag = "CS";
		}	
		// 11 cat C subcat C	
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("C") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("C")) ) {
			tag = "CC";
		}
		// 12 cat CL subcat suj
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("CL") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("suj")) ) {
			tag = "CLS";
		}
		// 13 cat CL subcat obj
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("CL") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("obj")) ) {
			tag = "CLO";
		}
		// 14 cat CL subcat refl
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("CL") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("refl")) ) {
			tag = "CLR";
		}
		// 15 cat P subcat 
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("P") ) {
			tag = "P";
		}	
		// 16 and 17 cat P ; it is necessary to look at the context (next w cat D/PRO)
		// 18 cat I subcat 
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("I") ) {
			tag = "I";
		}
		// 19 cat ET subcat 
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("ET") ) {
			tag = "ET";
		}
		// 20 cat PONCT subcat 
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("PONCT") ) {
			tag = "PONCT";
		}
		// 21 cat A subcat int
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("A") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("int")) ) {
			tag = "ADJWH";
		}
		// 22 cat A subcat not int
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("A") 
				&& (!((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("int")) ) {
			tag = "ADJ";
		}
		// 23 cat ADV subcat int
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("ADV") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("int")) ) {
			tag = "ADVWH";
		}
		// 24 cat ADV subcat not int
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("ADV") 
				&& (!((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("int")) ) {
			tag = "ADV";
		}
		// 25 cat PRO subcat int
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("PRO") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("int")) ) {
			tag = "PROWH";
		}
		// 26 cat PRO subcat rel
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("PRO") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("rel")) ) {
			tag = "PROREL";
		}
		// 27 cat PRO subcat not (int|rel)
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("PRO") 
				&& !(((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("int") 
						||((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("rel")
						) ) {
			tag = "PRO";
		}
		// 28 cat D subcat int
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("D") 
				&& (((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("int")) ) {
			tag = "DETWH";
		}
		// 29 cat D subcat not int
		else if (((String)wordMorphoSyntaxFeatures.get(cat)).equalsIgnoreCase("D") 
				&& (!((String)wordMorphoSyntaxFeatures.get(subcat)).equalsIgnoreCase("int")) ) {
			tag = "DET";
		}
		else {
			System.err.println("Warning: ftb 2 ftb+ unknown mapping case.  lemma "+ ((String)wordMorphoSyntaxFeatures.get(lemma))+ " cat "+ ((String)wordMorphoSyntaxFeatures.get(cat))+ " subcat "+ ((String)wordMorphoSyntaxFeatures.get(subcat)) + " mph "+ ((String)wordMorphoSyntaxFeatures.get(mph)));
			// By default return the cat value ; tag = ((String)wordMorphoSyntaxFeatures.get(cat);
		}
		return tag;
	}


}
